#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>

#include "number_detector.hpp"

int main(int argc, char** argv){
    std::string filename = "/home/ghowoght/workspace/edc2021_ws/src/xrobot/data/05.jpg";
    cv::Mat img = cv::imread(filename, cv::IMREAD_UNCHANGED);

    // cv::Mat img_temp = cv::imread("/home/ghowoght/workspace/edc2021_ws/src/xrobot/data/num4.jpg", cv::IMREAD_UNCHANGED);
    // cv::Mat img_test = cv::imread("/home/ghowoght/workspace/edc2021_ws/src/xrobot/data/num4_test.jpg", cv::IMREAD_UNCHANGED);

    // cv::Mat result_img;
    // cv::matchTemplate(img_test, img_temp, result_img, cv::TM_SQDIFF_NORMED);

    // float tmpCountMinVal = 0, tmpCountMaxVal = 0; 
    // cv::Point minPoint, maxPoint; 
    // // cv::minMaxLoc(result_img, &tmpCountMinVal, &tmpCountMaxVal
    // //                 , &minPoint, &maxPoint);

    NumberDetector detector;
    vector<vector<Point> > squares;

    // 寻找矩形
    detector.findSquares(img, squares);
    // 将数字区域提取出来
    std::vector<NumberArea> numberAreas;
    detector.getNumberArea(img, squares, numberAreas);
    
    cv::imshow("img", numberAreas[0].image);
    std::cout << "position: " << numberAreas[0].x << " " << numberAreas[0].y << std::endl;
    cv::waitKey(0);

    return 0; 
}